<?php
/**
 * alltosun.com 抱抱币规则
 * ============================================================================
 * 版权所有 (C) 2009-2011 北京互动阳光科技有限公司，并保留所有权利。
 * 网站地址: http://www.alltosun.com
 * ----------------------------------------------------------------------------
 * 许可声明：这是一个开源程序，未经许可不得将本软件的整体或任何部分用于商业用途及再发布。
 * ============================================================================
 * $Author: 高昂 (gaoa@alltosun.com) $
 * $Date: 2016-5-17 上午11:55:30 $
 * $Id: $
 */

class Action
{
    private $per_page = 20;
    
    /**
     * 抱抱币规则列表
     */
    public function index()
    {
        $page          = Request::Get('page_no', 1);
        $status        = Request::Get('status', 1);
        $is_advenced   = Request::Get('is_advenced', 0);
        $search_filter = Request::getParam('search_filter', array());
        
        //过滤条件
        $filter = array();
        $filter['status'] = $status;
        if (isset($search_filter['question']) && $search_filter['question']) {
            $filter[' `question` LIKE '] = $search_filter['question'].'%';
        }
        
        $bbcoin_rule_list  = array();
        $bbcoin_rule_count = _model('bbcoin_rule')->getTotal($filter);
        
        if ($bbcoin_rule_count) {
            $pager = new Pager($this->per_page);
            if ($pager->generate($bbcoin_rule_count)) {
                Response::assign('pager', $pager);
            }
            $bbcoin_rule_list = _model('bbcoin_rule')->getList($filter, ' ORDER BY `sort` DESC '.$pager->getLimit($page));
        }

        Response::assign('bbcoin_rule_list', $bbcoin_rule_list);
        Response::assign('status', $status);
        Response::assign('is_advenced', $is_advenced);
        Response::assign('search_filter', $search_filter);
        Response::display('admin/bbcoin_rule_list.html');
    }
    
    /**
     * 抱抱币规则添加页面
     */
    public function add()
    {
        Response::display('admin/add_bbcoin_rule.html');
    }
    
    /**
     * 抱抱币规则编辑页面
     */
    public function edit()
    {
        //接受id
        $id = Request::getParam('id', 0);
        if (!$id) {
        	return '请选择抱抱币规则';
        }
        $bbcoin_rule = _uri('bbcoin_rule', $id);
        
        Response::assign('is_edit', 1);
        Response::assign('bbcoin_rule', $bbcoin_rule);
        Response::display('admin/add_bbcoin_rule.html');
    }
    
    /**
     * 抱抱币规则更新
     */
    public function save()
    {
        //接受id
        $id = Request::getParam('id', 1);
        $bbcoin_rule = Request::getParam('bbcoin_rule', array());
        if (!$id) {
            return '请选择抱抱币规则';
        }
        
        _model('bbcoin_rule')->update($id, $bbcoin_rule);
        
        Response::redirect('bbcoin/admin/bbcoin_rule_list.html');
    }
    
    /**
     * 抱抱币规则填入
     */
    public function create()
    {
        // 接受数据
        $bbcoin_rule = Request::getParam('bbcoin_rule', array());
        if (!$bbcoin_rule['sort'] && $bbcoin_rule['sort'] != 0) {
        	$bbcoin_rule['sort'] = 1;
        }
//         an_dump($bbcoin_rule);
        _model('bbcoin_rule')->create($bbcoin_rule);
        
        Response::redirect('bbcoin/admin/bbcoin_rule_list.html');
    }
    
    /**
     * 抱抱币规则删除
     */
    public function delete()
    {
        //接受抱抱币规则id
        $id = Request::getParam('id');
        
        $ids = explode(',', $id);
        foreach ($ids as $k=>$v) {
            _model('bbcoin_rule')->update($v, array('status'=>0));
        }
        return 'ok';
    }
    
    /**
     * 抱抱币规则恢复
     */
    public function change_status()
    {
        //接受抱抱币规则id
        $id = Request::getParam('id');
        
        $ids = explode(',', $id);
        foreach ($ids as $k=>$v) {
            _model('bbcoin_rule')->update($v, array('status'=>1));
        }
         Response::redirect('bbcoin/admin/bbcoin_rule_list.html');
    }
    
    /**
     * 抱抱币规则销毁
     */
    public function delete_bbcoin_rule()
    {
        //接受抱抱币规则id
        $id = Request::getParam('id');
        
        $ids = explode(',', $id);
        foreach ($ids as $k=>$v) {
            _model('bbcoin_rule')->delete($v);
        }
        return 'ok';
    }
    
    
    
}


?>